package com.example.firstjavamqtt.controller.log_api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.firstjavamqtt.common.result.ResultCodeEnum;
import com.example.firstjavamqtt.service.log.DeviceLogService;
import com.example.firstjavamqtt.common.result.Result;
import com.example.firstjavamqtt.model.dto.log.DeviceLogDto;
import com.example.firstjavamqtt.model.log.DeviceLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/log/device")
@Api(tags = "设备日志接口")
public class DeviceLogController {

    @Autowired
    DeviceLogService deviceLogService;

    @ApiOperation(value = "分页获取设备日志列表")
    @GetMapping("/getAll/{pageNum}/{limit}")
        public Result getAllDeviceLog(@PathVariable int pageNum,
                                  @PathVariable int limit) {
        Page<DeviceLog> pageModel = deviceLogService.getAllDeviceLog(pageNum, limit);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "获取指定设备类型的设备日志列表")
    @GetMapping("/getAllByDeviceType/{deviceType}/{pageNum}/{limit}")
    public Result getAllDeviceLogByDeviceType(
            @PathVariable String deviceType,
            @PathVariable int pageNum,
            @PathVariable int limit) {
        Page<DeviceLog> pageModel = deviceLogService.getAllDeviceLogByDeviceType(deviceType, pageNum, limit);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "获取指定设备ID的设备日志列表")
    @GetMapping("/getAllByDeviceID/{deviceId}/{pageNum}/{limit}")
    public Result getAllDeviceLogByDeviceId(
            @PathVariable String deviceId,
            @PathVariable int pageNum,
            @PathVariable int limit) {
        Page<DeviceLog> pageModel = deviceLogService.getAllDeviceLogByDeviceId(deviceId, pageNum, limit);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "获取指定ID的设备日志")
    @GetMapping("/getDeviceLogById/{id}")
    public Result getDeviceLogById(@PathVariable int id) {
        DeviceLog deviceLog = deviceLogService.getDeviceLogById(id);
        return Result.ok(deviceLog);
    }

    @ApiOperation(value = "根据DeviceLogDto获取设备日志")
        @GetMapping("/getDeviceLog/{pageNum}/{limit}")
    public Result getDeviceLogByDto(
            @PathVariable int pageNum,
            @PathVariable int limit,
            DeviceLogDto deviceLogDto) {
        Page<DeviceLog> pageModel = deviceLogService.getDeviceLog(deviceLogDto, pageNum, limit);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "根据deviceId删除设备日志")
    @GetMapping("/deleteByDeviceId/{deviceId}")
    public Result deleteDeviceLogByDeviceId(@PathVariable String deviceId) {
        deviceLogService.deleteDeviceLogByDeviceId(deviceId);
        return Result.ok();
    }

    @ApiOperation(value = "根据deviceType删除设备日志")
    @GetMapping("/deleteByDeviceType/{deviceType}")
    public Result deleteDeviceLogByDeviceType(@PathVariable String deviceType) {
        deviceLogService.deleteDeviceByDeviceType(deviceType);
        return Result.ok();
    }

    @ApiOperation(value = "根据id删除设备日志")
        @GetMapping("/deleteById/{id}")
    public Result deleteDeviceLogByDeviceType(@PathVariable int id) {
        deviceLogService.deleteDeviceLogById(id);
        return Result.ok();
    }

    @ApiOperation(value = "根据批量id删除设备日志")
    @GetMapping("/deleteBatchId/{batchId}")
    public Result deleteDeviceLogByBatchId(@PathVariable ArrayList<Integer> batchId) {
        deviceLogService.deleteDeviceLogByBatchId(batchId);
        return Result.ok();
    }


}
